 # File：orm_test.py
# Author：信思智学
# Date ：2025/8/11 10:32
# Info：

import os
if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoORM20250807.settings")
    import django
    django.setup()
    from app.models import Book, Press, BookType


    #booktype = BookType.objects.get(id=1)
    #print(booktype)

    # 设置多对多关系
    #booktype.books.set([1,2,3])

    # 通过图书类型查找图书
    # booktype = BookType.objects.get(id=1)
    # print(booktype.books.all())

    # 通过图书查找图书类型
    # 方式一
    # 方式二
    # book = Book.objects.get(id=2)
    # print(book.booktype_set.all())

    book = Book.objects.filter(booktypes__id=1)
    print(book)











